function  results = shocks_generation( N_years,  par,  random_seed )
% Usage: shocks_generation( w_init, lambda_init,  N_years, par  )
% 
% Generate shocks for N_years at interval dt, starting from w_init and lambda_init.  The random seed is important.

if(nargin<=2) % not specifying random seeds
    random_seed = 1;
end

%% Parameters
dt = par.dt;
N_sim = round(N_years/dt);
lambdaHL = par.lambdaHL;  lambdaLH = par.lambdaLH;  
lambda_H = par.lambda_H;   lambda_L = par.lambda_L;
rng(random_seed);

%% dB shocks. Need to check the volatility of the price of capital!!!!!
% dB_vec = randn(N_sim, 1)*dt;
dB_vec = randn(N_sim, 1)*dt;

%%  Simulate the underlying process of lambda
lambda_MC = zeros( N_sim, 1 ); 
lambda = lambda_L;
random_vector1 = rand(N_sim, 1);
random_vector2 = rand(N_sim, 1);
for( i = 1:N_sim )
    lambda_MC(i) = lambda; 
    if(lambda==lambda_L && (random_vector1(i)<lambdaLH*dt))
        lambda = lambda_H;
    elseif(lambda==lambda_H && (random_vector2(i)<lambdaHL*dt))
        lambda = lambda_L;
    end
end
random_vector3 = rand(N_sim, 1);
% lambda_MC = (lambdaLH / (lambdaLH+lambdaHL) * lambda_H  + lambdaHL / (lambdaLH+lambdaHL) * lambda_L)  ;
dN_vec = random_vector3 < lambda_MC*dt ; 

%% Store Results
results.dB_vec = dB_vec;
results.dN_vec = dN_vec; 
results.lambda_MC = lambda_MC; 




